package cn.kevinking.ai.mcp.provider.utils;

import lombok.experimental.UtilityClass;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author jinkw
 */
@UtilityClass
public class BfzReflectionUtils {

    public List<Field> getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annoClazz) {
        List<Field> fields = new ArrayList<>();
        Class<?> iteratorClazz = clazz;
        while (iteratorClazz != null && iteratorClazz != Object.class) {
            fields.addAll(
                Arrays.stream(clazz.getDeclaredFields())
                        .filter(field -> field.isAnnotationPresent(annoClazz))
                        .toList()
            );
            iteratorClazz = iteratorClazz.getSuperclass();
        }
        return fields;
    }
}
